package com.hxt.util;

import org.joda.time.DateTime;

/**
 * 日期工具类
 * 
 * @author
 * 
 */
public class DateUtil {

	public static void main(String[] args) {
//		System.out.println(DateTime.now().plusDays(-6).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).toString("yyyy-MM-dd HH:mm:ss"));
//		System.out.println(DateTime.now().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59).toString("yyyy-MM-dd HH:mm:ss"));
//		
//		System.out.println(DateTime.now().plusMonths(-6).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).toString("yyyy-MM-dd HH:mm:ss"));
//		
//		DateTime dt =DateTime.now().plusDays(-1).withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59);
//		
//		DateTime dt1 =DateTime.now().plusDays(-7).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
//		System.out.println(dt.getMillis()/1000);
//		System.out.println(dt1.getMillis()/1000);
		
//		System.out.println(getCurDate235959());
//		System.out.println(getCurDateSubDay000000(-7));
//		System.out.println(getCurDateSubMonth000000(-1));
//		System.out.println(getCurDateSubMonth000000(-3));
//		System.out.println(getCurDateSubMonth000000(-12));
		
//		System.out.println(getCurDate000000());
//		System.out.println(getCurDate235959());
		
		System.out.println(getTime1730(1));
	}
	
	/**
	 * 返回当前服务器时间的23点59分59秒
	 * @return
	 */
	public static long getCurDate235959()
	{
		
		return DateTime.now().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59).getMillis()/1000;
	}
	
	/**
	 * 返回当前服务器时间的23点59分59秒
	 * @return
	 */
	public static long getCurDate000000()
	{
		
		return DateTime.now().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).getMillis()/1000;
	}
	
	/**
	 * 往前或后推几天的0时0分0秒的时间戳
	 * @param month
	 * @return
	 */
	public static long getCurDateSubDay000000(int day)
	{
		
		return DateTime.now().plusDays(day).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).getMillis()/1000;
	}
	/**
	 * 往前或后推分钟的时间戳
	 * @param month
	 * @return
	 */
	public static long getCurMinutesSub(int minute)
	{
		
		return DateTime.now().plusMinutes(minute).getMillis()/1000;
	}
	/**
	 * 往前或后推几月的0时0分0秒的时间戳
	 * @param month
	 * @return
	 */
	public static long getCurDateSubMonth000000(int month)
	{
		
		return DateTime.now().plusMonths(month).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).getMillis()/1000;
	}
	
	/**
	 * 返回时间戳
	 * @return
	 */
	public static int getToday() {
		Long currentTime = System.currentTimeMillis();
		currentTime = currentTime / 1000;

		return currentTime.intValue();
	}
	
	/**
	 * 返回长时间戳
	 * @return
	 */
	public static long getTodayL() {
		Long currentTime = System.currentTimeMillis();

		return currentTime.longValue();
	}
	
	/**
	 * 跟据type，返回七天，一个月，三个月，十天
	 * 返回长时间戳
	 * @return
	 */
	public static long getTime1730(int type) {
		long time=0l;
		if(type==1)//近七天
		{
			time=DateUtil.getCurDateSubDay000000(-7);
		}else if(type==2)//近一个月
		{
			time=DateUtil.getCurDateSubMonth000000(-1);
		}else if(type==3)//近三个月
		{
			time=DateUtil.getCurDateSubMonth000000(-3);
		}if(type==4)//近十天
		{
			time=DateUtil.getCurDateSubDay000000(-10);
		}
		return time;
	}
	
	
	/**
	 * 判断时间是否是当天时间
	 * 返回长时间戳
	 * @return
	 */
	public static boolean isCurTime(int time) {
	
		if(time<getCurDate235959() && time>getCurDate000000())
		{
			return true;
		}
		return false;
	}
	
}